//INTRINSICS
#include <xmmintrin.h>
#include <mmintrin.h>
#include <emmintrin.h>

typedef __m128 float4;
#define float4Sum(v) v.m128_u32[0]+v.m128_u32[1]+v.m128_u32[2]+v.m128_u32[3]
#define float4And(v) v.m128_u32[0]&&v.m128_u32[1]&&v.m128_u32[2]&&v.m128_u32[3]
#define float4Or(v) v.m128_u32[0]||v.m128_u32[1]||v.m128_u32[2]||v.m128_u32[3]
#define float4Unpack(v) v.m128_f32[0],v.m128_f32[1],v.m128_f32[2],v.m128_f32[3]
#define float4Elems(v) v.m128_f32
#define float4Elem(v,i) v.m128_f32[i]
#define float4Set _mm_setr_ps
#define float4Zero _mm_setzero_ps
#define float4Min _mm_min_ps
#define float4Max _mm_max_ps
inline float4 sqrt(float4 a) {return _mm_sqrt_ps(a);}
inline float4 rsqrt(float4 a) {return _mm_rsqrt_ps(a);}
inline float4 rcp(float4 a) {return _mm_rcp_ps(a);}

inline float4 operator + (float4 a, float4 b){return _mm_add_ps(a,b);}
inline float4 operator + (float4 a, float b){return a+_mm_set1_ps(b);}
inline float4 operator + (float a, float4 b){return _mm_set1_ps(a)+b;}
inline float4 operator += (float4 a, float4 b){return _mm_add_ps(a,b);}
inline float4 operator += (float4 a, float b){return a+_mm_set1_ps(b);}

inline float4 operator - (float4 a, float4 b){return _mm_sub_ps(a,b);}
inline float4 operator - (float4 a, float b){return a-_mm_set1_ps(b);}
inline float4 operator - (float a, float4 b){return _mm_set1_ps(a)-b;}
inline float4 operator -= (float4 a, float4 b){return _mm_sub_ps(a,b);}
inline float4 operator -= (float4 a, float b){return a-_mm_set1_ps(b);}

inline float4 operator * (float4 a, float4 b){return _mm_mul_ps(a,b);}
inline float4 operator * (float4 a, float b){return a*_mm_set1_ps(b);}
inline float4 operator * (float a, float4 b){return _mm_set1_ps(a)*b;}
inline float4 operator *= (float4 a, float4 b){return _mm_mul_ps(a,b);}
inline float4 operator *= (float4 a, float b){return a*_mm_set1_ps(b);}

inline float4 operator / (float4 a, float4 b){return _mm_div_ps(a,b);}
inline float4 operator / (float4 a, float b){return a/_mm_set1_ps(b);}
inline float4 operator / (float a, float4 b){return _mm_set1_ps(a)/b;}
inline float4 operator /= (float4 a, float4 b){return _mm_div_ps(a,b);}
inline float4 operator /= (float4 a, float b){return a/_mm_set1_ps(b);}

inline int operator == (float4 a, float4 b){float4 tmp=_mm_cmpeq_ps(a,b);return float4And(tmp);}
inline int operator != (float4 a, float4 b){float4 tmp=_mm_cmpneq_ps(a,b);return float4Or(tmp);}